<template>
  <div class="record-container">
    <!-- 搜索区域 -->
    <ContentWrap class="search-wrapper">
      <!-- 搜索头部 -->
      <div class="search-header">
        <div class="header-icon">
          <Icon icon="ep:phone" />
        </div>
        <div class="header-content">
          <h3 class="search-title">通话记录查询</h3>
          <p class="search-subtitle">管理和查看所有通话记录</p>
        </div>
        <div class="search-toggle">
          <el-button
            link
            type="primary"
            @click="searchType = 'senior'"
            v-if="searchType == 'ordinary'"
            class="toggle-btn"
          >
            <Icon icon="ep:search" class="btn-icon" />
            高级筛选
          </el-button>
          <el-button type="primary" link @click="searchType = 'ordinary'" v-else class="toggle-btn">
            <Icon icon="ep:search" class="btn-icon" />
            普通筛选
          </el-button>
        </div>
      </div>

      <!-- 高级筛选 -->
      <div v-if="searchType == 'senior'" class="advanced-search">
        <AdvancedScreening page="call_record" @search="handleAdavance" />
      </div>

      <!-- 普通搜索表单 -->
      <div v-if="searchType == 'ordinary'" class="ordinary-search">
        <el-form
          :model="queryParams"
          ref="queryFormRef"
          :inline="true"
          label-width="100px"
          label-position="left"
          class="enhanced-search-form"
        >
          <div class="form-grid">
            <el-form-item label="负责人" prop="ownerUserId" class="form-item">
              <el-select
                v-model="queryParams.ownerUserId"
                clearable
                filterable
                class="enhanced-select"
                placeholder="请选择负责人"
              >
                <template #prefix>
                  <Icon icon="ep:user" />
                </template>
                <el-option
                  v-for="item in userOptions"
                  :key="parseInt(item.id)"
                  :label="item.nickname"
                  :value="parseInt(item.id)"
                />
              </el-select>
            </el-form-item>

            <el-form-item label="坐席工号" prop="agentNumber" class="form-item">
              <el-input
                v-model="queryParams.agentNumber"
                placeholder="请输入坐席工号"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:postcard" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="被叫号码" prop="callee" class="form-item">
              <el-input
                v-model="queryParams.callee"
                placeholder="请输入被叫号码"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:phone" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="外呼类型" class="form-item">
              <el-select
                v-model="queryParams.callType"
                placeholder="请选择外呼类型"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:phone-filled" />
                </template>
                <el-option label="点呼" value="1" />
                <el-option label="群呼" value="2" />
                <el-option label="AI外呼" value="3" />
              </el-select>
            </el-form-item>

            <el-form-item label="创建时间" prop="createTime" class="form-item">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
                class="enhanced-date-picker"
              />
            </el-form-item>

            <el-form-item label="录音生成状态" prop="downloadStatus" class="form-item">
              <el-select
                v-model="queryParams.downloadStatus"
                placeholder="请选择录音生成状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:download" />
                </template>
                <el-option label="已生成" value="1" />
                <el-option label="未生成" value="0" />
              </el-select>
            </el-form-item>

            <el-form-item label="文字生成状态" prop="transStatus" class="form-item">
              <el-select
                v-model="queryParams.transStatus"
                placeholder="请选择状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:document" />
                </template>
                <el-option label="已生成" value="1" />
                <el-option label="未生成" value="0" />
                <el-option label="生成失败" value="-1" />
                <el-option label="进行中" value="9" />
              </el-select>
            </el-form-item>

            <el-form-item label="话单状态" class="form-item">
              <el-select
                v-model="queryParams.resultCode"
                placeholder="请选择状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:list" />
                </template>
                <el-option label="成功" value="success" />
                <el-option label="漏接" value="leak" />
                <el-option label="失败" value="faile" />
                <el-option label="错误" value="illegal" />
              </el-select>
            </el-form-item>

            <el-form-item label="呼叫结果" class="form-item">
              <el-select
                v-model="queryParams.resultType"
                placeholder="请选择状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:phone" />
                </template>
                <el-option label="呼叫成功" value="1" />
                <el-option label="播放语音时挂断" value="10" />
                <el-option label="播放语音完挂断" value="11" />
                <el-option label="系统线路异常" value="90" />
                <el-option label="黑名单或拦截" value="91" />
                <el-option label="空号或号码错误" value="92" />
                <el-option label="客户拒接或挂断" value="93" />
                <el-option label="客户忙或未接听" value="94" />
                <el-option label="坐席忙线未接听" value="95" />
                <el-option label="呼叫失败" value="99" />
              </el-select>
            </el-form-item>
          </div>

          <div class="form-actions">
            <el-button @click="handleQuery" class="search-btn">
              <Icon icon="ep:search" class="btn-icon" />
              搜索
            </el-button>
            <el-button @click="resetQuery" class="reset-btn">
              <Icon icon="ep:refresh" class="btn-icon" />
              重置
            </el-button>
            <el-button
              plain
              @click="handleExport"
              :loading="exportLoading"
              v-hasPermi="['call:record:export']"
              class="export-btn"
            >
              <Icon icon="ep:download" class="btn-icon" />
              导出
            </el-button>
          </div>
        </el-form>
      </div>
    </ContentWrap>

    <!-- 列表区域 -->
    <ContentWrap class="table-wrapper">
      <!-- 排序标签 -->
      <div class="sort-tags" v-if="sortTagList.length > 0">
        <div class="tags-header">
          <Icon icon="ep:sort" class="tags-icon" />
          <span class="tags-title">当前排序：</span>
        </div>
        <div class="tags-list">
          <el-tag
            @close="handleCloseTag(tag.label)"
            v-for="(tag, index) in sortTagList"
            :key="index"
            closable
            class="sort-tag"
            type="info"
          >
            {{ tag.name }}
            <el-icon v-if="tag.sort != 'desc'" class="sort-icon">
              <CaretTop />
            </el-icon>
            <el-icon v-else class="sort-icon">
              <CaretBottom />
            </el-icon>
          </el-tag>
        </div>
      </div>

      <!-- 标签页 -->
      <div class="tabs-container" v-if="searchType == 'ordinary'">
        <el-tabs v-model="activeName" @tab-click="handleTabClick" class="enhanced-tabs">
          <el-tab-pane label="我负责的" name="1">
            <template #label>
              <div class="tab-label">
                <Icon icon="ep:user" class="tab-icon" />
                <span>我负责的</span>
              </div>
            </template>
          </el-tab-pane>
          <el-tab-pane label="下属负责的" name="2">
            <template #label>
              <div class="tab-label">
                <Icon icon="ep:user-filled" class="tab-icon" />
                <span>下属负责的</span>
              </div>
            </template>
          </el-tab-pane>
          <el-tab-pane label="全部" name="0">
            <template #label>
              <div class="tab-label">
                <Icon icon="ep:menu" class="tab-icon" />
                <span>全部</span>
              </div>
            </template>
          </el-tab-pane>
        </el-tabs>
      </div>

      <!-- 表格 -->
      <div class="table-container">
        <el-table
          :header-cell-style="getRowClass"
          ref="sortTable"
          @sort-change="sortChange"
          v-loading="loading"
          :data="list"
          :stripe="true"
          border
          class="enhanced-table"
        >
          <el-table-column label="主叫信息" align="left" min-width="160">
            <template #default="scope">
              <div class="caller-info">
                <div class="info-item">
                  <Icon icon="ep:user" class="info-icon" />
                  <span class="info-label">员工：</span>
                  <span class="info-value">{{ scope.row.ownerUserName }}</span>
                </div>
                <div class="info-item">
                  <Icon icon="ep:postcard" class="info-icon" />
                  <span class="info-label">坐席：</span>
                  <span class="info-value">{{ scope.row.agentNumber }}</span>
                </div>
                <div class="info-item">
                  <Icon icon="ep:phone" class="info-icon" />
                  <span class="info-label">手机：</span>
                  <span class="info-value">{{ scope.row.telephone }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="被叫信息" align="left" min-width="180">
            <template #default="scope">
              <div class="callee-info">
                <div class="info-item">
                  <Icon icon="ep:phone" class="info-icon" />
                  <span class="info-label">号码：</span>
                  <span class="info-value">{{ scope.row.encryptCallee }}</span>
                </div>
                <div class="info-item">
                  <Icon icon="ep:location" class="info-icon" />
                  <span class="info-label">来源：</span>
                  <span class="info-value">{{ sourceMap[scope.row.source] || '其他' }}</span>
                </div>
                <div class="info-item">
                  <Icon icon="ep:user" class="info-icon" />
                  <span class="info-label">名称：</span>
                  <el-link type="primary" @click="seeDetail(scope.row)" class="name-link">
                    {{ scope.row.sourceName }}
                  </el-link>
                </div>
                <div v-if="scope.row.taskName" class="info-item">
                  <Icon icon="ep:document" class="info-icon" />
                  <span class="info-label">任务：</span>
                  <span class="info-value">{{ scope.row.taskName }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="外呼类型" align="center" prop="callTypeText" width="100px">
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.callType === '1'
                    ? 'primary'
                    : scope.row.callType === '2'
                      ? 'success'
                      : 'warning'
                "
                class="type-tag"
              >
                {{ scope.row.callTypeText }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column
            sortable="custom"
            label="呼叫结果"
            align="center"
            prop="resultType"
            width="120px"
          >
            <template #default="scope">
              <div class="result-info">
                <el-tag v-if="scope.row.resultCode == 'success'" type="success" class="result-tag">
                  <Icon icon="ep:check" class="tag-icon" />
                  成功
                </el-tag>
                <el-tag
                  v-else-if="scope.row.resultCode == 'leak'"
                  type="warning"
                  class="result-tag"
                >
                  <Icon icon="ep:warning" class="tag-icon" />
                  漏接
                </el-tag>
                <el-tag v-else-if="scope.row.resultCode == 'fail'" type="danger" class="result-tag">
                  <Icon icon="ep:close" class="tag-icon" />
                  失败
                </el-tag>
                <el-tag
                  v-else-if="scope.row.resultCode == 'illegal'"
                  type="info"
                  class="result-tag"
                >
                  <Icon icon="ep:info-filled" class="tag-icon" />
                  错误
                </el-tag>
                <span class="result-desc">{{ resultTypeMap[scope.row.resultType] }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="AI意向度"
            prop="summary"
            width="120"
            align="center"
            show-overflow-tooltip
          >
            <template #default="scope">
              <div class="ai-summary" v-if="scope.row.summary">
                <Icon icon="ep:cpu" class="ai-icon" />
                <span>{{ scope.row.summary }}</span>
              </div>
              <span v-else class="no-data">-</span>
            </template>
          </el-table-column>

          <el-table-column
            sortable="custom"
            label="应答时间"
            align="center"
            prop="startTime"
            :formatter="dateFormatter"
            width="180px"
          />

          <el-table-column
            sortable="custom"
            label="挂断时间"
            align="center"
            prop="endTime"
            :formatter="dateFormatter"
            width="180px"
          />

          <el-table-column
            sortable="custom"
            label="通话时长"
            align="left"
            prop="callSecond"
            min-width="140"
          >
            <template #default="scope">
              <div class="duration-info">
                <div class="duration-item">
                  <Icon icon="ep:timer" class="duration-icon" />
                  <span class="duration-label">通话:</span>
                  <span class="duration-value">{{ scope.row.callSecond }}秒</span>
                </div>
                <div class="duration-item">
                  <Icon icon="ep:money" class="duration-icon" />
                  <span class="duration-label">计费:</span>
                  <span class="duration-value">{{ scope.row.callMinute }}分</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            sortable="custom"
            width="150px"
            label="录音和文字"
            align="left"
            prop="downloadStatus"
          >
            <template #default="scope">
              <div class="media-status">
                <div class="status-item">
                  <Icon icon="ep:microphone" class="status-icon" />
                  <span class="status-label">录音：</span>
                  <el-tag
                    v-if="scope.row.downloadStatus"
                    type="success"
                    size="small"
                    class="status-tag"
                  >
                    已生成
                  </el-tag>
                  <el-tag v-else type="info" size="small" class="status-tag"> 未生成 </el-tag>
                </div>
                <div class="status-item">
                  <Icon icon="ep:document" class="status-icon" />
                  <span class="status-label">文字：</span>
                  <el-tag
                    v-if="scope.row.transStatus == 1"
                    type="success"
                    size="small"
                    class="status-tag"
                  >
                    已生成
                  </el-tag>
                  <el-tag
                    v-else-if="scope.row.transStatus == 0"
                    type="info"
                    size="small"
                    class="status-tag"
                  >
                    未生成
                  </el-tag>
                  <el-tag
                    v-else-if="scope.row.transStatus == -1"
                    type="danger"
                    size="small"
                    class="status-tag"
                  >
                    生成失败
                  </el-tag>
                  <el-tag
                    v-else-if="scope.row.transStatus == 9"
                    type="warning"
                    size="small"
                    class="status-tag"
                  >
                    进行中
                  </el-tag>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="创建时间"
            sortable="custom"
            align="center"
            prop="createTime"
            :formatter="dateFormatter"
            width="180px"
          />

          <el-table-column align="center" prop="remark" label="备注" min-width="120">
            <template #default="scope">
              <span v-if="scope.row.remark" class="remark-text">{{ scope.row.remark }}</span>
              <span v-else class="no-data">-</span>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" width="290px" fixed="right">
            <template #default="scope">
              <div class="flex">
                <el-button link type="primary" @click="openDetail(scope.row.id)" class="action-btn">
                  <Icon icon="ep:view" class="btn-icon" />
                  详情
                </el-button>
                <el-button
                  link
                  type="primary"
                  @click="downloadAudio(scope.row)"
                  :disabled="!scope.row.recordUrl"
                  class="action-btn"
                >
                  <Icon icon="ep:download" class="btn-icon" />
                  下载录音
                </el-button>
                <el-button
                  type="primary"
                  link
                  @click="transformCrmClue(scope.row)"
                  class="action-btn"
                >
                  <Icon icon="ep:share" class="btn-icon" />
                  转CRM线索
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </ContentWrap>

    <!-- 表单弹窗：添加/修改 -->
    <DetailDes ref="detailRef" @success="getList" />
    <!-- crm详情 -->
    <CrmSpec ref="crmSpec" @getPage="getList" />
    <!--企业详情  -->
    <EnterpriseDetails ref="companyDetail" @refresh-val="detailRefreList" />
    <!-- 新建线索弹窗 -->
    <ClueForm ref="clueForRef" />
  </div>
</template>

<script setup lang="ts">
import { call_dialog } from '@/api/sip/index.ts'
import { CaretTop, CaretBottom } from '@element-plus/icons-vue'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { RecordApi, RecordVO } from '@/api/call/record'
import DetailDes from './detail.vue'
import EnterpriseDetails from '@/views/ent/components/EnterpriseDetaill/index.vue'
import AdvancedScreening from '@/views/crm/components/AdvancedScreening/index.vue'
import * as AdvancedQueryApi from '@/api/crm/advancedQuery/index.ts'
import * as UserApi from '@/api/system/user'
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
import ClueForm from '@/views/crm/clue/ClueForm.vue'
import dayjs from 'dayjs'

/** 通话录音 列表 */
defineOptions({ name: 'Record' })

const message = useMessage() // 消息弹窗
const searchType = ref('ordinary')

const sourceMap = {
  ent: '企业大数据',
  clue: '线索',
  customer: '客户',
  contact: '联系人',
  none: '手拨'
}

const loading = ref(true) // 列表的加载中
const list = ref<RecordVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  telephone: undefined,
  agentNumber: undefined,
  callee: undefined,
  startTime: [],
  endTime: [],
  callSecond: undefined,
  callMinute: undefined,
  reqNo: undefined,
  ownerUserId: undefined,
  downloadStatus: undefined,
  createTime: [],
  sortFields: {},
  sortStr: JSON.stringify({ createTime: 'desc' }),
  sceneType: '1', // 默认和 activeName 相等
  transStatus: undefined,
  resultType: undefined,
  callType: undefined,
  resultCode: undefined
})
const activeName = ref('1') // 列表 tab

const resultTypeMap = {
  1: '呼叫成功',
  10: '播放语音时挂断',
  11: '播放语音完挂断',
  90: '系统线路异常',
  91: '黑名单或拦截',
  92: '空号或号码错误',
  93: '客户拒接或挂断',
  94: '客户忙或未接听',
  95: '坐席忙线未接听',
  99: '呼叫失败'
}
let closeTag = ref()
let isClearSort = ref(false)
const sortTagList = reactive([])
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
const crmSpec = ref(null)
/** tab 切换 */
const handleTabClick = (tab: TabsPaneContext) => {
  queryParams.sceneType = tab.paneName
  handleQuery()
}
const companyDetail = ref(null)
/** 线索的详情*/
const seeDetail = (item) => {
  if (item.source == 'none' || item.source == '') {
    return
  }
  // crm
  if (item.source == 'clue' || item.source == 'customer' || item.source == 'contact') {
    crmSpec.value.setDrawer(true, item.source, item.sourceId, [])
    // 企业大数据
  } else if (item.source == 'ent') {
    companyDetail.value.setDrawer(true, item.sourceId, null, null)
  }
}
const detailRefreList = () => {}
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    if (Object.keys(queryParams.sortFields).length > 0) {
      queryParams.sortStr = JSON.stringify(queryParams.sortFields)
    }

    let data
    if (searchType.value == 'senior') {
      if (!queryParams.params) return
      const obj = {
        pageNo: queryParams.pageNo,
        pageSize: queryParams.pageSize,
        params: queryParams.params
      }
      data = await AdvancedQueryApi.callAdvancePage(obj)
    } else {
      if (queryParams.params) delete queryParams.params
      data = await RecordApi.getRecordPage(queryParams)
    }
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

const initPage = () => {
  if (searchType.value == 'ordinary') {
    queryParams.pageNo = 1
    queryParams.params = null
    getList()
  }
}
/**线索的高级查询*/
const handleAdavance = async (item) => {
  queryParams.pageNo = 1
  queryParams.params = JSON.parse(item.params)
  getList()
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
} /** 关闭标签 */
const handleCloseTag = (label) => {
  delete queryParams.sortFields[label]
  sortTagList.splice(
    sortTagList.findIndex((i) => i.label === label),
    1
  )
  handleQuery()
  closeTag.value = label
}

/** 标签排序 */
const sortChange = (column) => {
  queryParams.sortFields[column.prop] = column.order == 'descending' ? 'desc' : 'asc'
  let label = column.column.label
  if (sortTagList.findIndex((i) => i.name === label) < 0) {
    sortTagList.push({
      name: label,
      sort: column.order == 'descending' ? 'desc' : 'asc',
      label: column.prop
    })
  } else {
    sortTagList.splice(
      sortTagList.findIndex((i) => i.name === label),
      1,
      {
        name: label,
        sort: column.order == 'descending' ? 'desc' : 'asc',
        label: column.prop
      }
    )
  }

  handleQuery()
  closeTag.value = ''
}

/** 处理样式 */
const getRowClass = ({ row, column, rowIndex, columnIndex }) => {
  if (column.property == closeTag.value) {
    column.order = ''
  }
}

const sortTable = ref()
/** 重置按钮操作 */
const resetQuery = () => {
  searchType.value = 'ordinary'
  queryParams.sortFields = {}
  sortTagList.length = 0
  closeTag.value = ''
  sortTable.value.clearSort()
  queryParams.resultType = undefined
  if (queryParams.params) delete queryParams.params
  queryFormRef.value?.resetFields()
  handleQuery()
}

// 下载录音
const downloadAudio = (row) => {
  if (row.recordUrl) {
    const link = document.createElement('a')
    link.href = row.recordUrl
    link.setAttribute('download', 'recording.mp4')
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
  }
}
/** 打开详情*/
const detailRef = ref()
const openDetail = (id: number) => {
  detailRef.value.open(id)
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await RecordApi.exportRecord(queryParams)
    download.excel(data, '通话录音.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}
const getUserOption = async () => {
  userOptions.value = await UserApi.getSimpleUserList()
}
const clueForRef = ref(null)
// 转crm线索
const transformCrmClue = async (item) => {
  try {
    const { clue } = await call_dialog({ number: item.callee, callId: '' })
    if (clue.length) {
      ElMessage.warning('已存在的线索')
      crmSpec.value.setDrawer(true, 'clue', clue[0], clue)
    } else {
      clueForRef.value.openByEnt('create', item.callee)
    }
  } catch {}
}
/** 初始化 **/
onMounted(() => {
  queryParams.createTime = [
    dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
    dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')
  ]
  getList()
  getUserOption()
})
</script>

<style lang="scss" scoped>
.record-container {
  padding: 16px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;

  @media (max-width: 768px) {
    padding: 8px;
  }
}

/* 搜索区域样式 */
.search-wrapper {
  margin-bottom: 16px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
}

.search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: linear-gradient(135deg, #0052cc 0%, #1d4ed8 100%);
  color: white;
  border-radius: 10px;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
  }
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;

  @media (max-width: 768px) {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

.header-content {
  flex: 1;
  margin-left: 16px;

  @media (max-width: 768px) {
    margin-left: 0;
    text-align: center;
  }
}

.search-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 18px;
  }
}

.search-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.search-toggle {
  flex-shrink: 0;
}

.toggle-btn {
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 500;
  transition: all 0.2s ease;

  &:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.advanced-search,
.ordinary-search {
  background: white;
  padding: 24px;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-search-form {
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 12px;

    @media (max-width: 768px) {
      grid-template-columns: 1fr;
      gap: 16px;
      margin-bottom: 20px;
    }
  }

  .form-item {
    margin-bottom: 0;

    :deep(.el-form-item__label) {
      font-weight: 500;
      color: #374151;
    }
  }
}

.enhanced-input,
.enhanced-select,
.enhanced-date-picker {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;

  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.search-btn {
  background: linear-gradient(135deg, #0052cc 0%, #1d4ed8 100%);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  color: white;

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.reset-btn {
  border: 2px solid #e5e7eb;
  color: #6b7280;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;

  &:hover {
    border-color: #d1d5db;
    color: #374151;
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.export-btn {
  border: 2px solid #0052cc;
  color: #0052cc;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;

  &:hover {
    background: rgba(0, 82, 204, 0.05);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 表格区域样式 */
.table-wrapper {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
}

.sort-tags {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: rgba(0, 82, 204, 0.05);
  border-bottom: 1px solid rgba(0, 82, 204, 0.1);

  @media (max-width: 768px) {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px;
  }
}

.tags-header {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tags-icon {
  color: #0052cc;
  font-size: 16px;
}

.tags-title {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sort-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-size: 12px;

  .sort-icon {
    font-size: 12px;
  }
}

.tabs-container {
  background: white;
  padding: 0 24px;

  @media (max-width: 768px) {
    padding: 0 16px;
  }
}

.enhanced-tabs {
  :deep(.el-tabs__header) {
    margin: 0;
    border-bottom: 2px solid #f1f5f9;
  }

  :deep(.el-tabs__nav-wrap) {
    &::after {
      display: none;
    }
  }

  :deep(.el-tabs__item) {
    padding: 16px 20px;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;

    &:hover {
      color: #0052cc;
    }

    &.is-active {
      color: #0052cc;
      border-bottom-color: #0052cc;
    }
  }
}

.tab-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-icon {
  font-size: 14px;
}

.table-container {
  background: white;
  overflow-x: auto;
}

.enhanced-table {
  :deep(.el-table__header) {
    background: #f8fafc;

    th {
      background: #f8fafc !important;
      color: #374151;
      font-weight: 600;
      border-bottom: 2px solid #e5e7eb;
    }
  }

  :deep(.el-table__row) {
    &:hover {
      background: rgba(0, 82, 204, 0.02) !important;
    }
  }

  :deep(.el-table__cell) {
    padding: 12px 8px;
    border-bottom: 1px solid #f1f5f9;
  }
}

/* 表格内容样式 */
.caller-info,
.callee-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.info-icon {
  color: #6b7280;
  font-size: 12px;
  flex-shrink: 0;
}

.info-label {
  color: #6b7280;
  font-weight: 500;
  flex-shrink: 0;
}

.info-value {
  color: #1f2937;
  font-weight: 500;
}

.name-link {
  font-size: 12px;
  font-weight: 500;
}

.type-tag {
  font-size: 12px;
  font-weight: 500;
}

.result-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.result-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;

  .tag-icon {
    font-size: 12px;
  }
}

.result-desc {
  font-size: 11px;
  color: #6b7280;
  text-align: center;
  line-height: 1.2;
}

.ai-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #1f2937;

  .ai-icon {
    color: #0052cc;
    font-size: 14px;
  }
}

.duration-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.duration-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

.duration-icon {
  color: #6b7280;
  font-size: 12px;
  flex-shrink: 0;
}

.duration-label {
  color: #6b7280;
  font-weight: 500;
  flex-shrink: 0;
}

.duration-value {
  color: #1f2937;
  font-weight: 500;
}

.media-status {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

.status-icon {
  color: #6b7280;
  font-size: 11px;
  flex-shrink: 0;
}

.status-label {
  color: #6b7280;
  font-weight: 500;
  flex-shrink: 0;
}

.status-tag {
  font-size: 10px;
  padding: 2px 6px;
}

.no-data {
  color: #9ca3af;
  font-size: 12px;
}

.remark-text {
  font-size: 12px;
  color: #1f2937;
  line-height: 1.4;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;

  @media (max-width: 768px) {
    gap: 8px;
  }
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;

  &:hover {
    background: rgba(0, 82, 204, 0.1);
  }

  &:disabled {
    color: #9ca3af;
    cursor: not-allowed;

    &:hover {
      background: transparent;
    }
  }

  .btn-icon {
    font-size: 12px;
  }
}

.pagination-wrapper {
  padding: 20px 24px;
  background: white;
  border-top: 1px solid #f1f5f9;

  @media (max-width: 768px) {
    padding: 16px;
  }

  :deep(.el-pagination) {
    justify-content: center;

    @media (max-width: 768px) {
      .el-pagination__sizes,
      .el-pagination__jump {
        display: none;
      }
    }
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .record-container {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  }

  .search-wrapper,
  .table-wrapper {
    background: #374151;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .ordinary-search,
  .advanced-search,
  .tabs-container,
  .table-container,
  .pagination-wrapper {
    background: #374151;
  }

  .search-title {
    color: #f9fafb;
  }

  .info-value,
  .duration-value,
  .ai-summary,
  .remark-text {
    color: #f9fafb;
  }

  .info-label,
  .duration-label,
  .status-label,
  .info-icon,
  .duration-icon,
  .status-icon {
    color: #d1d5db;
  }

  .enhanced-table {
    :deep(.el-table__header) {
      background: #4b5563;

      th {
        background: #4b5563 !important;
        color: #f9fafb;
        border-bottom-color: #6b7280;
      }
    }

    :deep(.el-table__cell) {
      border-bottom-color: #4b5563;
    }
  }

  .enhanced-tabs {
    :deep(.el-tabs__header) {
      border-bottom-color: #4b5563;
    }

    :deep(.el-tabs__item) {
      color: #d1d5db;

      &:hover,
      &.is-active {
        color: #60a5fa;
      }

      &.is-active {
        border-bottom-color: #60a5fa;
      }
    }
  }
}
</style>
